﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using KTool2.Utility;

namespace KTool2
{
    /// <summary>
    /// Interaction logic for TranslateCondition.xaml
    /// </summary>
    public partial class TranslateConditionWindow : Window
    {
        private volatile static TranslateConditionWindow instance = null;
        //public AppSetting setting;

        private TranslateConditionWindow()
        {
            InitializeComponent();
            //this.setting = setting;
            this.TranslateRateArray = AppSetting.Instance.RateShowingArray;
        }

        public bool[] TranslateRateArray
        {
            get
            {
                return new Boolean[]
                {
                    this.chkbx1Star.IsChecked.Value,
                    this.chkbx2Star.IsChecked.Value,
                    this.chkbx3Star.IsChecked.Value,
                    this.chkbx4Star.IsChecked.Value,
                    this.chkbx5Star.IsChecked.Value
                };
            }
            set
            {
                this.chkbx1Star.IsChecked = value[0];
                this.chkbx2Star.IsChecked = value[1];
                this.chkbx3Star.IsChecked = value[2];
                this.chkbx4Star.IsChecked = value[3];
                this.chkbx5Star.IsChecked = value[4];
            }
        }

        public static TranslateConditionWindow Instance
        {
            get
            {
                if (instance == null)
                {
                    System.Threading.Mutex mutex = new System.Threading.Mutex();
                    mutex.WaitOne();

                    if (instance == null)
                    {
                        instance = new TranslateConditionWindow();
                    }

                    mutex.Close();
                }

                return instance;
            }
        }

        public static bool IsNull
        {
            get { return instance == null; }
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            AppSetting.Instance.RateShowingArray = this.TranslateRateArray;
            this.Close();
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            instance = null;
        }
    }
}
